package 剑指offer;

/**
 * @description:
 * @author: ywk
 * @date: 2021-03-13
 */
public class 四键键盘 {
    static int count = 0;

    static int MAXA(int n, int num, int copy) {
        count++;
        if (n <= 0) {
            return num;
        }
        return Math.max(Math.max(MAXA(n - 1, num + 1, copy), MAXA(n - 1, num + copy, copy)), MAXA(n - 2, num, num));
    }

    static int MAXV(int n) {
        int[] dp = new int[n + 1];
        dp[0] = 0;
        for (int i = 1; i <= n; i++) {
            //按A
            dp[i] = dp[i - 1] + 1;
            for (int j = 2; j < i; j++) {
                dp[i] = Math.max(dp[i], dp[j - 2] * (i - j + 1));
            }
        }
        return dp[n];
    }

    public static void main(String[] args) {
        System.out.println(MAXA(20, 0, 0));
        System.out.println(MAXV(20));
        System.out.println(count);
    }
}